// 长度的最小的子数组 滑动窗口
// target = 7, nums = [2,3,1,2,4,3]
/**
 * @param {number} target
 * @param {number[]} nums
 * @return {number}
 */
var minSubArrayLen = function (target, nums) {
  let len = nums.length
  let result = len
  let num = 0
  let flag = false

  for (let i = 0, j = 0; j < len; j++) {
    num += nums[j]
    while (num >= target) {
      flag = true
      result = Math.min(result, j - i + 1)
      num -= nums[i]
      i++
    }
  }

  return flag ? result : 0
};

console.log(minSubArrayLen(7, [2, 3, 1, 2, 4, 3]));
